home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-13 | 11.7 KB | 470 lines | [TEXT/CWIE] |
-
- //===============================================================================
- //===============================================================================
- //
- // Picker Demo
- //
- // john calhoun 1997
- //
- //===============================================================================
- //===============================================================================
-
-
- #include "TestPicker.h"
-
-
- pascal Boolean SimpleEventFilter (EventRecord *);
- pascal void SimpleColorFilter (long, PMColorPtr);
- pascal void NSimpleColorFilter (long, NPMColorPtr);
- void main (void);
-
-
- PickerCWRec gSyncWorld;
- CMColor cmykColor;
- RgnHandle wholeVenn, regionR, regionG, regionB, blackRgn;
- RgnHandle regionRG, regionGB, regionBR, regionRGB;
- Rect windowBounds, rectC, rectM, rectY, rectK;
- RGBColor theRGBColor;
- MenuRef appleMenu, fileMenu, editMenu, testMenu;
- WindowRef simpleWindow;
- Boolean quitting, memoryAlert, resForkAlert;
-
-
- //===================================================================== Functions
- //--------------------------------------------------------------------- SimpleGetColor
-
- void SimpleGetColor (void)
- {
- Point where;
- Boolean colorChanged;
-
- SetPt(&where, 0, 0);
-
- colorChanged = GetColor(where, "\pBoring, old GetColor().", &theRGBColor, &theRGBColor);
- if (colorChanged)
- {
- SetPort(simpleWindow);
- InvalRect(&windowBounds);
- }
- }
-
- //--------------------------------------------------------------------- SimpleEventFilter
-
- #if GENERATINGCFM
- RoutineDescriptor SimpleEventFilterRD =
- BUILD_ROUTINE_DESCRIPTOR (uppUserEventProcInfo, SimpleEventFilter);
- #endif
-
- pascal Boolean SimpleEventFilter (EventRecord *theEvent)
- {
- WindowPtr whichWindow;
- SInt32 menuChoice;
- SInt16 thePart;
- Boolean handledIt;
-
- handledIt = false;
-
- switch (theEvent->what)
- {
- case mouseDown:
- thePart = FindWindow(theEvent->where, &whichWindow);
- switch (thePart)
- {
- case inSysWindow:
- SystemClick(theEvent, whichWindow);
- break;
-
- case inMenuBar:
- menuChoice = MenuSelect(theEvent->where);
- handledIt = DoMenuChoice(menuChoice);
- break;
- }
- break;
-
- case updateEvt:
- handledIt = DoUpdateEvent(theEvent);
- break;
- }
-
- UpdateBouncingLine();
-
- return (handledIt);
- }
-
- //--------------------------------------------------------------------- SimpleColorFilter
-
- #if GENERATINGCFM
- RoutineDescriptor SimpleColorFilterRD =
- BUILD_ROUTINE_DESCRIPTOR (uppColorChangedProcInfo, SimpleColorFilter);
- #endif
-
- pascal void SimpleColorFilter (long userData, PMColorPtr newColor)
- {
- #pragma unused (userData)
- GrafPtr wasPort;
- long csVers;
- CMError syncError;
- CMWorldRef syncWorld;
- CMColor theColor;
- OSErr theErr;
-
- GetPort(&wasPort);
- SetPort(simpleWindow);
-
- theErr = Gestalt(gestaltColorMatchingVersion, &csVers);
- if ((newColor->profile) && (theErr == noErr))
- {
- syncError = CWNewColorWorld(&syncWorld, newColor->profile, 0L);
- if ((syncError == noErr) || (syncError == cmProfilesIdentical))
- {
- theColor = newColor->color;
- CWMatchColors(syncWorld, &theColor, 1);
- CWDisposeColorWorld(syncWorld);
- }
- }
- else
- theColor.rgb = newColor->color.rgb;
-
- theRGBColor.red = theColor.rgb.red;
- theRGBColor.green = theColor.rgb.green;
- theRGBColor.blue = theColor.rgb.blue;
-
- UpdateVennColors();
- UpdateBouncingLine();
-
- SetPort(wasPort);
- }
-
- //--------------------------------------------------------------------- NSimpleColorFilter
-
- #if GENERATINGCFM
- RoutineDescriptor NSimpleColorFilterRD =
- BUILD_ROUTINE_DESCRIPTOR (uppNColorChangedProcInfo, NSimpleColorFilter);
- #endif
-
- pascal void NSimpleColorFilter (long userData, NPMColorPtr newColor)
- {
- #pragma unused (userData)
- GrafPtr wasPort;
- CMColor theColor;
-
- theColor = newColor->color;
-
- if (GetProfileColorSpace(newColor->profile) == cmCMYKData)
- {
- cmykColor = newColor->color;
- UpdateCMYKColors();
- }
-
- PickerMatchColors(&gSyncWorld, &theColor, 1);
-
- theRGBColor.red = theColor.rgb.red;
- theRGBColor.green = theColor.rgb.green;
- theRGBColor.blue = theColor.rgb.blue;
-
- GetPort(&wasPort);
- SetPort(simpleWindow);
-
- UpdateVennColors();
- UpdateBouncingLine();
-
- SetPort(wasPort);
- }
-
- //--------------------------------------------------------------------- PickColorMovableModal
-
- void PickColorMovableModal (long pickerType)
- {
- ColorPickerInfo theColorInfo;
- RGBColor wasColor;
- UserEventUPP simpleEventFilterUPP;
- ColorChangedUPP simpleColorFilterUPP;
- OSErr theErr;
-
- wasColor = theRGBColor;
-
- #if GENERATINGCFM
- simpleEventFilterUPP = &SimpleEventFilterRD;
- simpleColorFilterUPP = &SimpleColorFilterRD;
- #else
- simpleEventFilterUPP = &SimpleEventFilter;
- simpleColorFilterUPP = &SimpleColorFilter;
- #endif
-
- theColorInfo.placeWhere = kCenterOnMainScreen;
- theColorInfo.dialogOrigin.h = 0;
- theColorInfo.dialogOrigin.v = 0;
-
- theColorInfo.mInfo.editMenuID = 130;
- theColorInfo.mInfo.undoItem = 1;
- theColorInfo.mInfo.cutItem = 3;
- theColorInfo.mInfo.copyItem = 4;
- theColorInfo.mInfo.pasteItem = 5;
- theColorInfo.mInfo.clearItem = 6;
-
- theColorInfo.dstProfile = 0L;
- theColorInfo.pickerType = pickerType;
- theColorInfo.flags = DialogIsMoveable | DialogIsModal | CanModifyPalette |
- CanAnimatePalette | CallColorProcLive;
- theColorInfo.eventProc = simpleEventFilterUPP;
- theColorInfo.colorProc = simpleColorFilterUPP;
- theColorInfo.colorProcData = 0L;
-
- theColorInfo.theColor.profile = 0;
- theColorInfo.theColor.color.rgb.red = theRGBColor.red;
- theColorInfo.theColor.color.rgb.green = theRGBColor.green;
- theColorInfo.theColor.color.rgb.blue = theRGBColor.blue;
-
- if (pickerType == 'HTML')
- PasStringCopy("\pHTML Picker is brought up alone.", theColorInfo.prompt);
- else
- PasStringCopy("\pThis is the fancy PickColor().", theColorInfo.prompt);
-
- theErr = PickColor(&theColorInfo);
-
- if ((theErr == noErr) && (theColorInfo.newColorChosen))
- {
- theRGBColor.red = theColorInfo.theColor.color.rgb.red;
- theRGBColor.green = theColorInfo.theColor.color.rgb.green;
- theRGBColor.blue = theColorInfo.theColor.color.rgb.blue;
- SetPort(simpleWindow);
- InvalRect(&windowBounds);
- }
- else
- {
- theRGBColor = wasColor;
- SetPort(simpleWindow);
- InvalRect(&windowBounds);
- }
- }
-
- //--------------------------------------------------------------------- NPickColorMovableModal
-
- void NPickColorMovableModal (void)
- {
- NColorPickerInfo theColorInfo;
- RGBColor wasColor;
- UserEventUPP simpleEventFilterUPP;
- NColorChangedUPP simpleColorFilterUPP;
- CMProfileRef destProfile;
- Handle profileHandle;
- OSErr theErr;
-
- // Get SWOP profile
- profileHandle = GetResource('prof', -16002);
- if (!profileHandle)
- goto fail;
- DetachResource(profileHandle);
- theErr = OpenProfileHandle(&destProfile, profileHandle, 0L,
- cmPerceptual);
- if (theErr)
- goto fail;
-
- wasColor = theRGBColor;
-
- #if GENERATINGCFM
- simpleEventFilterUPP = &SimpleEventFilterRD;
- simpleColorFilterUPP = &NSimpleColorFilterRD;
- #else
- simpleEventFilterUPP = &SimpleEventFilter;
- simpleColorFilterUPP = &NSimpleColorFilter;
- #endif
-
- theColorInfo.placeWhere = kCenterOnMainScreen;
- theColorInfo.dialogOrigin.h = 0;
- theColorInfo.dialogOrigin.v = 0;
-
- theColorInfo.mInfo.editMenuID = 130;
- theColorInfo.mInfo.undoItem = 1;
- theColorInfo.mInfo.cutItem = 3;
- theColorInfo.mInfo.copyItem = 4;
- theColorInfo.mInfo.pasteItem = 5;
- theColorInfo.mInfo.clearItem = 6;
-
- theColorInfo.dstProfile = destProfile;
- theColorInfo.pickerType = 0L;
- theColorInfo.flags = DialogIsMoveable | DialogIsModal | CanModifyPalette |
- CanAnimatePalette | AppIsColorSyncAware | CallColorProcLive;
- theColorInfo.eventProc = simpleEventFilterUPP;
- theColorInfo.colorProc = simpleColorFilterUPP;
- theColorInfo.colorProcData = 0L;
-
- theColorInfo.theColor.profile = 0L;
- theColorInfo.theColor.color.rgb.red = theRGBColor.red;
- theColorInfo.theColor.color.rgb.green = theRGBColor.green;
- theColorInfo.theColor.color.rgb.blue = theRGBColor.blue;
-
- PasStringCopy("\pSoft proof with a profile.", theColorInfo.prompt);
-
- theErr = NPickerNewColorWorld(&gSyncWorld,
- theColorInfo.theColor.profile, theColorInfo.dstProfile, 0L,
- cmRGBData, cmRGBData);
- if (theErr != noErr)
- {
- SysBeep(10);
- }
-
- theErr = NPickColor(&theColorInfo);
-
- if ((theErr == noErr) && (theColorInfo.newColorChosen))
- {
- PickerMatchColors(&gSyncWorld, &(theColorInfo.theColor.color), 1);
-
- theRGBColor.red = theColorInfo.theColor.color.rgb.red;
- theRGBColor.green = theColorInfo.theColor.color.rgb.green;
- theRGBColor.blue = theColorInfo.theColor.color.rgb.blue;
- SetPort(simpleWindow);
- InvalRect(&windowBounds);
- }
- else
- {
- theRGBColor = wasColor;
- SetPort(simpleWindow);
- InvalRect(&windowBounds);
- }
-
- (void) CMCloseProfile(destProfile);
- if (profileHandle)
- DisposeHandle(profileHandle);
- PickerDisposeColorWorld(&gSyncWorld);
-
- return;
-
- fail:
-
- SysBeep(10);
- if (profileHandle)
- DisposeHandle(profileHandle);
-
- return;
- }
-
- //--------------------------------------------------------------------- NPickColorCMYK
-
- void NPickColorCMYK (void)
- {
- NColorPickerInfo theColorInfo;
- CMColor wasColor;
- UserEventUPP simpleEventFilterUPP;
- NColorChangedUPP simpleColorFilterUPP;
- CMProfileRef inOutProfile;
- Handle profileHandle;
- OSErr theErr;
-
- // Get Color LW 12/600 PS profile
- profileHandle = GetResource('prof', -16000);
- if (!profileHandle)
- goto fail;
- DetachResource(profileHandle);
- theErr = OpenProfileHandle(&inOutProfile, profileHandle, 0L, cmPerceptual);
- if (theErr)
- goto fail;
-
- wasColor = cmykColor;
-
- #if GENERATINGCFM
- simpleEventFilterUPP = &SimpleEventFilterRD;
- simpleColorFilterUPP = &NSimpleColorFilterRD;
- #else
- simpleEventFilterUPP = &SimpleEventFilter;
- simpleColorFilterUPP = &NSimpleColorFilter;
- #endif
-
- theColorInfo.placeWhere = kCenterOnMainScreen;
- theColorInfo.dialogOrigin.h = 0;
- theColorInfo.dialogOrigin.v = 0;
-
- theColorInfo.mInfo.editMenuID = 130;
- theColorInfo.mInfo.undoItem = 1;
- theColorInfo.mInfo.cutItem = 3;
- theColorInfo.mInfo.copyItem = 4;
- theColorInfo.mInfo.pasteItem = 5;
- theColorInfo.mInfo.clearItem = 6;
-
- theColorInfo.dstProfile = 0L;
- theColorInfo.pickerType = 'CMYK';
- theColorInfo.flags = DialogIsMoveable | DialogIsModal | CanModifyPalette |
- CanAnimatePalette | AppIsColorSyncAware | CallColorProcLive;
- theColorInfo.eventProc = simpleEventFilterUPP;
- theColorInfo.colorProc = simpleColorFilterUPP;
- theColorInfo.colorProcData = 0L;
-
- theColorInfo.theColor.profile = inOutProfile;
- theColorInfo.theColor.color = cmykColor;
-
- PasStringCopy("\pPick a color in CMYK space.", theColorInfo.prompt);
-
- theErr = NPickerNewColorWorld(&gSyncWorld,
- theColorInfo.theColor.profile, theColorInfo.dstProfile, 0L,
- cmCMYKData, cmRGBData);
- if (theErr)
- goto fail;
-
- theErr = NPickColor(&theColorInfo);
-
- if ((theErr == noErr) && (theColorInfo.newColorChosen))
- {
- cmykColor = theColorInfo.theColor.color;
-
- PickerMatchColors(&gSyncWorld, &(theColorInfo.theColor.color), 1);
-
- theRGBColor.red = theColorInfo.theColor.color.rgb.red;
- theRGBColor.green = theColorInfo.theColor.color.rgb.green;
- theRGBColor.blue = theColorInfo.theColor.color.rgb.blue;
- SetPort(simpleWindow);
- InvalRect(&windowBounds);
- }
- else
- {
- cmykColor = wasColor;
- SetPort(simpleWindow);
- InvalRect(&windowBounds);
- }
-
- (void) CMCloseProfile(inOutProfile);
- DisposeHandle(profileHandle);
- PickerDisposeColorWorld(&gSyncWorld);
-
- return;
-
- fail:
-
- SysBeep(10);
- if (profileHandle)
- DisposeHandle(profileHandle);
- return;
- }
-
- //--------------------------------------------------------------------- main
-
- void main (void)
- {
- InitToolbox();
- AddMenusToMenuBar();
- OpenSimpleWindow();
- AllocateVennColorDiagramRegions();
- SetUpCMYKRects();
- SetUpBounceLine();
-
- theRGBColor.red = RandomInt(32767) << 1;
- theRGBColor.green = RandomInt(32767) << 1;
- theRGBColor.blue = RandomInt(32767) << 1;
-
- cmykColor.cmyk.cyan = RandomInt(32767) << 1;
- cmykColor.cmyk.magenta = RandomInt(32767) << 1;
- cmykColor.cmyk.yellow = RandomInt(32767) << 1;
- cmykColor.cmyk.black = RandomInt(32767) << 1;
-
- quitting = false;
-
- do
- {
- EventLoop();
- }
- while (!quitting);
-
- if (theGWorld)
- DisposeGWorld(theGWorld);
- }
-
-